/*
 * @lc app=leetcode.cn id=748 lang=javascript
 *
 * [748] 最短补全词
 */

// @lc code=start
/**
 * @param {string} licensePlate
 * @param {string[]} words
 * @return {string}
 */
var shortestCompletingWord = function(licensePlate, words) {
    let count={}
    licensePlate= licensePlate.toLowerCase()
    let str="qazwsxedcrfvtgbyhnujmikolp"
    for(let i=0;i<licensePlate.length;i++){
        if(str.includes(licensePlate[i])){
            if(count[licensePlate[i]]){
                count[licensePlate[i]]++
            }else{
                count[licensePlate[i]]=1
            }
        }
    }
    let res=[]
    let minLen=Infinity
    function flit(item){
        let countCopy=Object.assign({},count)
        for(let i=0;i<item.length;i++){
            if(countCopy[item[i]]){
                countCopy[item[i]]--
            }
        }
        for(let i in count){
            if(countCopy[i]>0)return false
        }
        minLen=Math.min(minLen,item.length)
        return true
    }
    res=words.filter((item)=>{
        return flit(item)
    })
    return res.filter((item)=>{
        return item.length==minLen
    })[0]
};
// @lc code=end

